 package com.lihongman.util;

import java.util.List;

public class Page<T> {
	private int totalNums;
	private int pageSize;
	private int pageNum;
	private List<T> result;
	
	public Page(int pageSize,int totalNums,int pageNum){
		setPageSize(pageSize);
		setTotalNums(totalNums);
		setPageNum(pageNum);
	}
	
	public Page(int totalNums,int pageNum){
		this(5, totalNums, pageNum);
	}
	
	public int getTotalNums() {
		return totalNums;
	}
	public void setTotalNums(int totalNums) {
		this.totalNums = totalNums;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		if(pageNum < 1){
			pageNum=1;
		}else if(pageNum > getTotalPages()){
			pageNum = getTotalPages();
		}
		this.pageNum = pageNum;
	}
	public List<T> getResult() {
		return result;
	}
	public void setResult(List<T> result) {
		this.result = result;
	}
	public int getTotalPages(){
		int total = this.getTotalNums()/this.pageSize;
		if(this.totalNums % this.pageSize != 0){
			total += 1;
		}
		return total;
	}
	public int getStartNum(){
		int num = (this.pageNum-1)*this.pageSize;
		return num;
	}
}
